from selenium.webdriver.common.by import By
from appium.webdriver.common.touch_action import TouchAction
import time

from ZUtils import connect_app,get_elements,input_text,is_located,get_element,handler_swipe
#连接
driver=connect_app()

#打开作业帮页面
driver.start_activity('com.baidu.homework','activity.index.IndexActivity')
#点击登录
time.sleep(3)
login=get_element(driver,By.XPATH,'//*[@text="未登录"]')
login.click()

#点击今日签到
time.sleep(3)
sign=get_element(driver,By.XPATH,'//*[@text="签到"]')
sign.click()

#点击密码登录
time.sleep(3)
pw=get_element(driver,By.XPATH,'//*[@text="密码"]')
pw.click()

#输入用户名
user=get_element(driver,By.XPATH,'//*[@text="输入手机号码"]')
username=input("输入用户名")
input_text(user,username)

#输入密码
pw=get_element(driver,By.XPATH,'//*[@text="请输入登录密码"]')
password=input("请输入密码")
input_text(pw,password)

#点击登录
time.sleep(3)
denglu=get_element(driver,By.XPATH,'//*[@text="登录"]')
denglu.click()

#点击返回
time.sleep(8)
#fanhui=is_located(driver,By.XPATH,'//*[@text=""]')
#fanhui.click()
driver.press_keycode(4)

#点击商城
time.sleep(3)
shopping=is_located(driver,By.ID,'com.baidu.homework:id/user_item_title')
shopping.click()

#点击文具
time.sleep(16)
wenju=is_located(driver,By.XPATH,'//*[@text="文具"]')
wenju.click()

#下滑
time.sleep(3)
handler_swipe('up',driver)
print('下滑结束')

#回退一次
time.sleep(3)
driver.press_keycode(4)
time.sleep(3)
handler_swipe('up',driver)
#ht1=is_located(driver,By.XPATH,'//*[@text=""]')
#ht1.click()
#点击回退
#time.sleep(5)
driver.press_keycode(4)

#点击首页
time.sleep(2)
index=get_element(driver,By.XPATH,'//*[@text="首页"]')
index.click()

#下滑
time.sleep(3)
handler_swipe('up',driver)
handler_swipe('up',driver)


#点击内容
neiro=get_element(driver,By.ID,'com.baidu.homework:id/stuc_user_publish_ll')
neiro.click()

#点击评论输入框
time.sleep(3)
comment=get_element(driver,By.XPATH,'//*[@text="我来说两句"]')
comment_bu=get_element(driver,By.XPATH,'//*[@text="发送"]')
a4='加油'
comment.send_keys(a4)
comment_bu.click()


driver.quit()
